/**
 * 
 */
package com.btpn.infra.utils;

import com.btpn.custody.common.Constant;

/**
 * @author Firmansyah
 *
 */
public class ErrorMessageUtil {

	public static String getErrorHTML(String message){
		if (message == null) {
			return "Please contact administrator.";
		}
		
		if (message.indexOf("java.net.SocketException") != -1) {
			if (message.indexOf("Network is unreachable: connect") != -1) {
				return "Koneksi terputus";
			}
			if (message.indexOf("Connection reset by peer") != -1) {
				if (message.indexOf("socket write error") != -1) return "ClientAbortException";
			}
		}
		
		if (message.indexOf("java.sql.SQLException") != -1) {
//			if (message.indexOf("ORA-02292") != -1) {
//				if (message.indexOf("T_SALES_ID_R01") != -1) {
//					return "Database exception: This user is used by sales productivity module";
//				} else if (message.indexOf("FK_R_MPP") != -1) {
//					return "Database exception: This user is used by other user(s) as parent";
//				} else {
//					return "Database exception: This data is used by other data(s)";
//				}
//			}
//			if(message.indexOf("ORA-00001") != -1){
//				if (message.indexOf("T_CAS_DEPO_PK") != -1) {
//					return "Database exception: Data(s) already exist on deposit table";
//				} else if(message.indexOf("T_CAS_CASA_PK") != -1){
//					return "Database exception: Data(s) already exist on CASA table";
//				} else {
//					return "Database exception: Unique constraint";
//				}
//				
//			}
			
			if(message.equals(Constant.E_ACC_DUP)){
				return Constant.E_ACC_DUP;
			}
			
			return "Database exception";
		}

		if (message.indexOf("org.hibernate.exception.ConstraintViolationException") != -1) {		
			return "Data still in use";
		}
		
//		StringBuffer sb = new StringBuffer();
//		sb.append("<table class=\"tblDomain\"  align=\"center\" style=\"display: inline\">																																										   ");   
//		sb.append("		<tr height=\"20px\">                                                                                                                                      ");  
//		sb.append("			<td class=\"tdTitle\" width=\"100%\"><table><tr><td width=\"100%\">The application caught an unexpected exception.</td><td><a href=\"#\" id=\"errorRef\"><span id=\"span-arrow\" class=\"icon-up\"></span></a></td></tr></table></td>																														   ");   
//		sb.append("		</tr>																																																																	   	");	 
//		sb.append("		<tr>																																																																	   	");		
//		sb.append("			<td class=\"tdContent\">																																																							   		");
//		//sb.append("					To view the error details click <a href=\"#\" id=\"errorRef\">here</a>.    "); 
//		sb.append("					<div id=\"errorReport\" class=\"displayNone\">																											   		");
//		sb.append("					<table border=\"0\" cellspacing=\"0\" cellpadding=\"4\" width=\"100%\">																																	   	");  
//		sb.append("						<tr><td valign=\"top\">"+ message.replaceAll("\n", "<br/>") + "</td></tr>																																										   	");        
//		sb.append("					</table>																																																												   	");  
//		sb.append("					</div>																																																													   		");
//		sb.append("			</td>																																																																   	");  
//		sb.append("		</tr>																																																																	   	");  
//		sb.append("</table>																																																																	   	");  
//
//		return sb.toString();
		return "unknown";
	}
}
